home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1996 #15
/
Monster Media Number 15 (Monster Media)(July 1996).ISO
/
utils
/
4cd.zip
/
4CD.BTM
next >
Wrap
Text File
|
1996-04-10
|
16KB
|
463 lines
@echo off
*if exist %TEMP\4cd.dir *del /q %TEMP\4cd.dir
*set _dbpath=%@path[%@search[4cd]]
*iff %1/ eq / then
*cd
*quit
*endiff
*iff %1/ eq /?/ then
*gosub helpinfo
*quit
*endiff
*iff %1/ eq /ABOUT/ then
*gosub aboutinfo
*quit
*endiff
:start
*if %1/ eq / *quit
*set _opt=%@upper[%1]
*iff %@index[%_opt,/MD] ne -1 then
:mkloop
*shift
*if %1/ eq / *quit
*iff %@index[%1,/] eq -1 then
*gosub MakeDir
*endiff
*if %@index[%1,/] eq -1 *goto /I mkloop
*goto start
*quit
*elseiff %@index[%_opt,/RD] ne -1 then
:rmloop
*shift
*if %1/ eq / *quit
*iff %@index[%1,/] eq -1 then
*gosub RemoveDir
*endiff
*if %@index[%1,/] eq -1 *goto /I rmloop
*goto start
*quit
*elseiff %@index[%_opt,/SCAN] ne -1 then
*shift
*gosub Scan
*goto start
*quit
*elseiff %@index[%_opt,/ADD] ne -1 then
:addloop
*shift
*if %1/ eq / *quit
*iff %@index[%1,/] eq -1 then
*set _dr=%1
*gosub Add
*endiff
*if %@index[%1,/] eq -1 *goto /I addloop
*goto start
*quit
*elseiff %@index[%_opt,/DIRALIAS] ne -1 then
*shift
:aliasloop
*if %1/ eq / *quit
*iff %@index[%1,/] eq -1 then
*gosub Diralias
*endiff
*if %@index[%1,/] eq -1 *goto /I aliasloop
*goto start
*quit
*elseiff %@index[%_opt,/DELALIAS] ne -1 then
:delaliasloop
*shift
*if %1/ eq / *quit
*iff %@index[%1,/] eq -1 then
*gosub DelAlias
*endiff
*if %@index[%1,/] eq -1 *goto /I delaliasloop
*goto start
*quit
*elseiff %@index[%_opt,/CD] ne -1 then
*shift
*goto start
*quit
*elseiff %@index[%_opt,/PWD] ne -1 then
*shift
*echo %_cwd
*goto start
*quit
*elseiff %@index[%_opt,/FILE] ne -1 then
*shift
*for %_i in (@%_dbpath\4CD.SEQ) do (
*iff %@ready[%@word["\",0,%_i]] eq 1 then
*iff exist %_i\%1 then
*echo ==%@char[16] %_i\%1
*inkey /K"YyNn" Change to this directory? (y/n) %%_ynq
*set _ynq=%@UPPER[%_ynq]
*iff %_ynq eq Y then
*cdd %_i
*shift
*unset _i _ynq
*goto start
*endiff
*endiff
*endiff
)
*shift
*goto start
*quit
*elseiff %@index[%_opt,/!FILE] ne -1 then
*shift
*for %_i in (@%_dbpath\4CD.SEQ) do (
*iff %@ready[%@word["\",0,%_i]] eq 1 then
*iff exist %_i\%1 then
*cdd %_i
*shift
*unset _i
*goto start
*endiff
*endiff
)
*else
*iff isdir %1 then
*cdd %1
*quit
*elseiff $%1 eq $\ then
*cdd \
*quit
*elseiff $%1 eq $- then
*cdd -
*quit
*elseiff $%1 eq $* then
*set _dest=.
*set _dest=%@select[%_dbpath\4cd.seq,0,10,10,60,Change Directory]
*iff $%_dest ne $ then
*set _4dr=%@substr[%_dest,0,2]
*iff %@removable[%_4dr] ne 1 then
*cdd %_dest
*else
*do forever
*iff %@ready[%_4dr] eq 1 then
*iff isdir %_dest then
*cdd %_dest
leave
*endiff
*endiff
*echo Please mount volume with %_dest in %_4dr.
*pause
*enddo
*endiff
*endiff
*quit
*endiff
*setlocal
*echos Scanning database for "%1"...
*gosub findalias
*iff %_found eq 1 then *unset _found
*else
*FFIND /KMVT"%@UPPER[%1]" %_dbpath\4CD.SEQ > %TEMP\4CD.$$$
*for %_i in (@%TEMP\4CD.$$$) do if %@index[%@word["\",-0,%_i],%1] ne -1 echo %_i >>! %TEMP\4CD.DIR
*del /q %temp\4cd.$$$
*endiff
*echo done.
*endlocal
*iff not exist %TEMP\4cd.dir then
*echo %1 cannot be found in the database.
*echo You may need to regenerate the database (use %0 /SCAN),
*echo or add a removable drive to the database (use %0 /ADD).
*elseiff %@lines[%TEMP\4cd.dir] eq 0 then
*cdd %@line[%TEMP\4cd.dir,0]
*del /Q %TEMP\4cd.dir
*else
*set _dest=.
*set _dest=%@select[%TEMP\4cd.dir,0,10,10,60,Change to "%1"]
*iff $%_dest ne $ then
*set _4dr=%@substr[%_dest,0,2]
*iff %@removable[%_4dr] ne 1 then
*cdd %_dest
*else
*do forever
*iff %@ready[%_4dr] eq 1 then
*iff isdir %_dest then
*cdd %_dest
leave
*endiff
*endiff
*echo Please mount volume with %_dest in %_4dr.
*pause
*enddo
*endiff
*endiff
*del /Q %TEMP\4cd.dir
*quit
*endiff
*shift
*goto start
*endiff
*quit
*rem Remove a directory and delete it from the database
:RemoveDir
*iff exist %@full[%1]\*.* then
*beep
*echo %@upper[%@full[%1]] is not empty. It cannot be removed.
*quit
*endiff
*echos Removing directory %@upper[%@full[%1]]...
*rd %@full[%1]
*echo done.
*echos Updating database...
*move /Q %_dbpath\4cd.seq %TEMP\4cd.old
*setlocal
*set _dbhandle=%@fileopen[%TEMP\4CD.OLD,READ]
*if %_dbhandle eq -1 *goto dberror
*set _newhandle=%@fileopen[%_dbpath\4CD.SEQ,WRITE]
*if %_newhandle eq -1 *goto dberror
*set _curln=%@fileread[%_dbhandle]
do until "%_curln" eq "**EOF**"
*iff %@upper[%1] ne %@upper[%_curln] then
*set _err=%@filewrite[%_newhandle,%_curln]
*endiff
set _curln=%@fileread[%_dbhandle]
*enddo
*set _dbhandle=%@fileclose[%_dbhandle]
*if %_dbhandle eq -1 *goto dberror
*set _newhandle=%@fileclose[%_newhandle]
*if %_newhandle eq -1 *goto dberror
*del /Q %TEMP\4cd.old
*echo done.
*endlocal
*return
*rem Create a new directory and add it to the database
:MakeDir
*echos Creating %@upper[%@full[%1]]...
*md %@full[%1]
*echo done.
*echos Updating database...
*echo %@full[%1] >>! %_dbpath\4cd.seq
*echo done.
*return
*rem Regenerate the database
:Scan
*if exist %_dbpath\4cd.seq *del /Q %_dbpath\4cd.seq
*echo Scanning drives for directories...
*for %i in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
*set _dr=%i:
*gosub Add
)
*echo done.
*echo Database created.
*return
*rem Add a drive to the database
:Add
*iff %@ready[%_dr] eq 1 then
*echos Adding %_dr to database...
*dir/efsba:d %_dr\ >>! %_dbpath\4cd.seq
*echo done.
*endiff
*return
*rem Create a new alias for a directory.
:Diralias
*setlocal
*iff not exist %_dbpath\4cd.als then
*echo %@upper[%1] %@upper[%2] >! %_dbpath\4cd.als
*else
*move /q %_dbath\4cd.als %temp\4cdals.old
*set _aliashandle=%@fileopen[%temp\4CDALS.OLD,READ]
*if %_aliashandle eq -1 *goto dberror
*set _newhandle=%@fileopen[%_dbpath\4CD.ALS,WRITE]
*if %_newhandle eq -1 *goto dberror
*set _written=0
*do until "%_curln" eq "**EOF**"
*set _curln=%@fileread[%_aliashandle]
*iff %@upper[%1] eq %@upper[%@word[0,%_curln]] then
*set _err=%@filewrite[%_newhandle, %@upper[%1] %@upper[%2]]
*if %_err eq -1 goto dberror
*set _written=1
*else
*set _err=%@filewrite[%_newhandle,%_curln]
*if %_err eq -1 goto dberror
*endiff
*enddo
*iff %_written eq 0 then
*set _err=%@filewrite[%_newhandle,%@upper[%1] %@upper[%2]]
*endiff
*set _aliashandle=%@fileclose[%_aliashandle]
*if %_aliashandle eq -1 *goto dberror
*set _newhandle=%@fileclose[%_newhandle]
*if %_newhandle eq -1 *goto dberror
*shift
*shift
*endiff
*if exist %temp\4cdals.old *del /q %temp\4cdals.old
*endlocal
*return
*rem Delete an alias for a directory.
:delalias
*setlocal
*move /q %_dbpath\4cd.als %temp\4cdals.old
*set _oldhandle=%@fileopen[%temp\4CDALS.OLD,READ]
*if %_oldhandle eq -1 *goto dberror
*set _newhandle=%@fileopen[%_dbpath\4CD.ALS,WRITE]
*if %_newhandle eq -1 *goto dberror
*set _currln=%@fileread[%_oldhandle]
*do until "%_currln" eq "**EOF**"
*iff %@upper[%@word[0,%_currln]] ne %@upper[%1] then
*set _err=%@filewrite[%_newhandle,%_currln]
*if %_err eq -1 goto dberror
*endiff
*set _currln=%@fileread[%_oldhandle]
*enddo
*set _oldhandle=%@fileclose[%_oldhandle]
*if %_oldhandle eq -1 *goto dberror
*set _newhandle=%@fileclose[%_newhandle]
*if %_newhandle eq -1 *goto dberror
*del /q %temp\4cdals.old
*endlocal
*return
*rem Search the alias database for the chosen directory
:findalias
*if not exist %_dbpath\4cd.als *return
*set _found=0
*set _dbhandle=%@fileopen[%_dbpath\4CD.ALS,READ]
*if %_dbhandle eq -1 *goto dberror
*set _currln=%@fileread[%_dbhandle]
*do until "%_currln" eq "**EOF**"
*iff %@upper[%1] eq %@upper[%@word[0,%_currln]] then
*echo %@word[1,%_currln] >> %temp\4cd.dir
*set _found=1
*endiff
*iff %_found ne 1 then
*set _currln=%@fileread[%_dbhandle]
*else
*goto closefiles
*endiff
*enddo
:closefiles
*set _dbhandle=%@fileclose[%_dbhandle]
*if %_dbhandle eq -1 *goto dberror
*return
*rem Help information
:helpinfo
cls
*text
Usage: 4CD [/MD | /RD | [/CD] dir [...]]
Create, remove, and change directories
/MD Create the directories whose names follow, until the next
switch
/RD Remove the directories whose names follow, until the next
switch
/CD Change the current directory to the one whose name follows.
/CD is optional if it is the first switch on the line.
If no arguments are supplied to 4CD, the current working directory
will be displayed.
dir is the name of a directory or directory alias (see below).
Usage: 4CD - Change back to the directory you were in when you last issued
a CD, CDD, or 4CD command
Usage: 4CD * Select a directory to change to from a scrolling list.
endtext
*pause
*cls
*text
Usage: 4CD /FILE filename
Search for the file specified and change to the directory
it is found in. You are asked whether you want to change
to the indicated directory.
Usage: 4CD /!FILE filename
As 4CD /FILE, except that the change is automatic to the
directory in which the file is first found.
endtext
*pause
*cls
*text
Usage: 4CD /DIRALIAS alias dir [...] Attach an alias to a directory
alias is the alias (nickname) that you want to attach
to the directory.
dir is the directory to attach the alias to. It
should be a full specification (i.e., include
the drive and all higher level directories).
Usage: 4CD /DELALIAS alias [...] Delete a directory alias
alias is the directory alias to remove from the alias list.
endtext
*pause
*cls
*text
Usage: 4CD /SCAN Rescan disks for directories.
Only drives C: through Z: will be
scanned. Removable drives, including
CD-ROMs, which are currently mounted
will be scanned.
Usage: 4CD /ADD d: [...] Add one or more drives to the
database. You may add drives
A: and B:, or add additional
removable media (ZIP, JAZZ,
EZ-DRIVE, CD-ROM, etc.) using
this option.
Usage: 4CD /PWD Display the current directory.
endtext
*pause
*cls
*text
Any number of commands may be combined on a single line,
in any order.
Deleting a directory alias does not remove the directory, and
removing the directory does not remove any aliases referring to
that directory.
endtext
*return
:aboutinfo
*text
4CD was written by Jeff Zeitlin to see if it could be done.
I can be contacted in the ILink Shareware and 4DOS conferences,
or via Internet at jeff.zeitlin@execnet.com or in the
comp.os.msdos.4dos newsgroup.
4CD is copyright 1993-1996 Jeff Zeitlin. All rights reserved.
4CD may be shared with users of 4DOS and compatible command
processors, as long as this ABOUT information and copyright
notice remain included and unaltered. If you think it's worth
paying for, contact me at one of the above electronic
locations.
endtext
*return
:dberror
*text
An error has occurred trying to access the directory database.
It may be in use by another copy of 4CD, or another program.
Please make sure that no other program and no other copy of 4CD
is attempting to use the directory database. If no other
program and no other copy of 4CD is trying to use the directory
database, your FILES setting in CONFIG.SYS is probably too
small, or some other problem with file handles exists. Please
correct the problem and retry 4CD.
endtext